<template>
  <div class='tab-controller'>
    <div class="tab-controller-item" 
    :class="{active: index === currentIndex}"
    v-for="(item,index) in titles" :key="item.id"
    @click="itemClick(index)">
      <span>
        {{ item.title }}
      </span>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'TabController',
    props: {
      titles: {
        type:Array,
        default(){
          return [];
        }
      } 
    },
     data() {
      return {
        currentIndex:0
      }
    },
    methods: {
      itemClick (index) {
        this.currentIndex=index;
        // 切换tab页分类显示
        this.$emit('tabChange', index);
      }
    }
  }
</script>
<style scoped>
  .tab-controller {
    display: flex;
    text-align: center;
    font-size: 15px;
    background-color: #fff;
  }
  .tab-controller-item {
    flex: 1;
    height: 40px;
    line-height: 40px

  }
  .tab-controller-item span {
    padding: 5px;
  }
  .active {
    color: var(--color-tint);
  }
  .active span{
    border-bottom: 2px solid var(--color-tint);
  }
</style>




